package model

import (
	"gorm.io/gorm"
)

var Dao *ServiceContext

func InitTaskLog(db *gorm.DB) {
	migrator := db.Migrator()
	if !migrator.HasTable(&TaskLog{}) {
		migrator.CreateTable(&TaskLog{})
	} else {
		migrator.AutoMigrate(&TaskLog{})
	}
	if !migrator.HasTable(&TaskLogDetails{}) {
		migrator.CreateTable(&TaskLogDetails{})
	}
	Dao = NewServiceContext(db)
}

type ServiceContext struct {
	TTask    TaskLogMoodle
	TTaskLog TaskLogDetailMoodle
}

func NewServiceContext(db *gorm.DB) *ServiceContext {
	return &ServiceContext{
		TTask:    *NewTaskLogMoodle(db),
		TTaskLog: *NewTaskLogDetailMoodle(db),
	}
}
